﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using NHibernate;
using NUnit.Framework.Constraints;
using NUnit.Framework;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace SAKS.UnitTest
{
    public class TestManager
    {
        
        private ISessionFactory _sessionFactory;
        private static Configuration nhConfig;

        public ISessionFactory SessionFactory
        {
            get
            {
                return _sessionFactory;
            }
        }

        private TestManager()
        {
            FileInfo finfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "\\Log4net.cfg.xml");
            log4net.Config.XmlConfigurator.Configure(finfo);

            nhConfig = new ConfigurationBuilder().Build();

            _sessionFactory = nhConfig.BuildSessionFactory();
        }
        private static TestManager provider;

        public static void RefreshDatabase()
        {
            var schemaExport = new SchemaExport(nhConfig);
            schemaExport.SetOutputFile(@"db.sql").Execute(false, true, false);//测试开始时删除数据库内所有数据 
        }
        public static TestManager GetInstance()
        {
            if (provider == null)
            {
                provider = new TestManager();
            }
            return provider;
        }
    }
}
